package com.example.codegen.common;

import oracle.jdbc.*;
import oracle.jdbc.driver.DatabaseError;
import oracle.jdbc.oracore.OracleNamedType;
import oracle.sql.*;

import java.math.BigDecimal;
import java.sql.*;
import java.util.Map;

/**
 * oracle.jdbc.driver.StructMetaData
 * oracle.jdbc.driver.OracleResultSetMetaData
 * oracle.jdbc.driver.OracleDatabaseMetaData
 * oracle.jdbc.driver.OracleParameterMetaDataParser
 * oracle.jdbc.OracleType
 * oracle.jdbc.oracore.OracleType
 * 参考文档： https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/accessing-and-manipulating-Oracle-data.html
 */
public class OracleDBType {
/*

    public String getColumnClassName(String typeName) throws SQLException {

        OracleTypes types;


        OracleType oracleType = null;
        for (OracleType item : OracleType.values()) {
            if (item.getName().equals(typeName)) {
                oracleType = item;
                break;
            }
        }
        if (oracleType == null) {
            throw new RuntimeException("不支持的oracle数据类型");
        }
        switch (oracleType.getVendorTypeNumber()) {
            case 1:
            case 8:
            case 96:
            case 999:
                return String.class.getName();
            case 2:
            case 6:
                if (this.getDescription()[index].precision != 0 && this.getDescription()[index].scale == -127) {
                    return Double.class.getName();
                }
                return BigDecimal.class.getName();
            case 12:
                return Timestamp.class.getName();
            case 23:
            case 24:
                return byte[].class.getName();
            case 100:
                return Float.class.getName();
            case 101:
                return Double.class.getName();
            case 102:
                return OracleResultSet.class.getName();
            case 104:
            case 208:
                return ROWID.class.getName();
            case 109:
                switch (this.getColumnType(column)) {
                    case 2002:
                        Map<String, Class<?>> map = this.connection.getTypeMap();
                        if (map != null) {
                            Class<?> c = (Class) map.get(((OracleNamedType) this.getDescription()[index].describeOtype).getFullName());
                            if (c != null) {
                                return c.getName();
                            }
                        }

                        return OracleStruct.class.getName();
                    case 2003:
                        return OracleArray.class.getName();
                    case 2004:
                    case 2005:
                    case 2006:
                    default:
                        throw (SQLException) DatabaseError.createSqlException(this.getConnectionDuringExceptionHandling(), 1).fillInStackTrace();
                    case 2007:
                        return OracleOpaque.class.getName();
                    case 2008:
                        OracleNamedType ntype = (OracleNamedType) this.getDescription()[index].describeOtype;
                        Map<String, Class<?>> map = this.connection.getJavaObjectTypeMap();
                        if (map != null) {
                            Class<?> c = (Class) map.get(ntype.getFullName());
                            if (c != null) {
                                return c.getName();
                            }
                        }

                        return StructDescriptor.getJavaObjectClassName(this.connection, ntype.getSchemaName(), ntype.getSimpleName());
                    case 2009:
                        return SQLXML.class.getName();
                }
            case 111:
                return OracleRef.class.getName();
            case 112:
                if (this.getDescription()[index].formOfUse == 2) {
                    return OracleNClob.class.getName();
                }

                return OracleClob.class.getName();
            case 113:
                return OracleBlob.class.getName();
            case 114:
                return OracleBfile.class.getName();
            case 119:
            default:
                return Object.class.getName();
            case 180:
                if (this.statement.connection.j2ee13Compliant) {
                    return Timestamp.class.getName();
                }

                return TIMESTAMP.class.getName();
            case 181:
                return TIMESTAMPTZ.class.getName();
            case 182:
                return INTERVALYM.class.getName();
            case 183:
                return INTERVALDS.class.getName();
            case 231:
                return TIMESTAMPLTZ.class.getName();
            case 252:
                return Boolean.class.getName();
        }
    }
*/

    public static void main(String[] args) {
        String typeName = "TIMESTAMP(6) WITH LOCAL TIME ZONE";
        String oracleTypeName = typeName.replaceAll("\\([^()]*\\)", "").replaceAll(" ", "_");
        System.out.println(oracleTypeName);

        OracleType oracleType = OracleType.valueOf(oracleTypeName);
        System.out.println(oracleType);
    }
}
